package com.zh.app.dao.impl;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate4.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.zh.app.dao.UserDao;
import com.zh.app.model.User;

@Component("userDao")
public class UserDaoImpl implements UserDao {

	// private SessionFactory sessionFactory;
	//
	// public SessionFactory getSessionFactory() {
	// return sessionFactory;
	// }
	//
	// @Resource(name="sessionFactory")
	// public void setSessionFactory(SessionFactory sessionFactory) {
	// this.sessionFactory = sessionFactory;
	// }

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource(name="hibernateTemplate")
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	@Override
	public void save(User u) {
//		Session session = sessionFactory.getCurrentSession();
		// session.beginTransaction();
//		session.save(u);
		// session.getTransaction().commit();
		hibernateTemplate.save(u);
		System.out.println("a user saved");
	}

}
